import {isPlainObject,isString} from 'lodash';
const changeStyle = (obj) => {
    for (let key in obj) {
        //重新赋值自己之前定义的less变量值
        document
            .getElementsByTagName('body')[0]
            .style.setProperty(`--${key}`, obj[key]);
    }
};

export const subject={
    DL:{
        allbackground: '#0081FF',
        allfontcolor: '#fff',
        searchbackground: '#fff',
        titleBgColor:'rgba(0, 129, 255, .5)'
    },
    LS:{
        allbackground: '#F48A06',
        allfontcolor: '#fff',
        searchbackground: '#fff',
        titleBgColor:'rgba(242, 170, 80, .5)'
    },
    YY:{
        allbackground: '#5D6B7E',
        allfontcolor: '#fff',
        searchbackground: '#fff',
        titleBgColor:'rgba(93, 107, 126, .5)'
    }
}
const setTheme = (themeName=null) => {
    let themeConfig = isString(themeName)?subject[themeName]:false;
    if(isPlainObject(themeConfig)){
        sessionStorage.setItem("themeConfig", JSON.stringify(themeConfig)); 
    }else{
        let themeConfig=sessionStorage.getItem("themeConfig");
        try{
            themeConfig=isString(themeConfig) && isPlainObject(JSON.parse(themeConfig))?themeConfig:null;
        }catch(e){
            themeConfig=null;
        }
        themeConfig=themeConfig?themeConfig:subject['DL'];
    }
    changeStyle(themeConfig);
};

export default setTheme;